home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / clrkbbuf.arc / CLRKBBUF.ASM next >
Encoding:
Assembly Source File  |  1985-11-21  |  8.0 KB  |  227 lines

  1.       PAGE     60,132
  2.       TITLE CLRKBBUF- Clear Keyboard Buffer
  3. ;      Written by Lew Paper
  4. ;      11/21/85
  5.  
  6.       PAGE
  7. ;-----------------------------------------------------------------------------
  8. ; SWITCH SETTINGS
  9. ;-----------------------------------------------------------------------------
  10.  
  11. params    EQU    'N'                   ;'Y' means command line parameters
  12. dos2dirs  EQU    'N'                   ;'Y' means DOS 2+ directory searches
  13.  
  14. ;-----------------------------------------------------------------------------
  15. ; INITIAL DIRECTIVES
  16. ;-----------------------------------------------------------------------------
  17.  
  18. ;Standard handles
  19. StdIn      EQU     0               ;Standard input device
  20. Stdout      EQU     1               ;Standard output device
  21. Stderr      EQU     2               ;Standard error device
  22. Stdaux      EQU     3               ;Standard auxiliary device
  23. Stdprn      EQU     4               ;Standard printer device
  24.  
  25. COMSEG    SEGMENT PARA PUBLIC 'CODE'
  26.       ASSUME CS:COMSEG,DS:COMSEG,ES:COMSEG,SS:COMSEG
  27.  
  28.           IF params EQ 'Y'
  29.       ORG     7FH
  30. cmd_leng  DB     ?               ;Set to 127 and call DOS function
  31.                        ;0AH to reenter a command string
  32. cmdcnt      DB     ?               ;Command line character count
  33. cmdstr      DB     127 DUP (?)           ;Command line buffer
  34.           ENDIF                        ;PARAMS EQ 'Y'
  35.  
  36.       ORG     100H
  37. start      PROC     FAR
  38.       JMP     ENTRY
  39.  
  40. ;-----------------------------------------------------------------------------
  41. ; DATA AREAS
  42. ;-----------------------------------------------------------------------------
  43.  
  44. exitval   DB     0               ;Exit value
  45. done_mes  DB     'Keyboard buffer cleared',13,10
  46. done_len  EQU     $ - done_mes
  47.  
  48.           IF dos2dirs EQ 'Y'
  49.  
  50. oldDTA:   DW     ?               ;To save old DTA offset
  51.  
  52. time_rec  RECORD hour:5, minute:6, pair_sec:5
  53.                        ;pair_sec is two second increments
  54.  
  55. date_rec  RECORD year:7, month:4, day:5
  56.                        ;Year 0 is 1980
  57.  
  58. dos2DTA   STRUC                ;Structure for dos 2+ DTA
  59.                        ;after directory search
  60.       DB     21 DUP (?)           ;Reserved for DOS use
  61. attr      DB     ?               ;Attribute
  62. time      DW     ?               ;time_rec, but records illegal in STRUC
  63. date      DW     ?               ;date_rec, but records illegal in STRUC
  64. lo_size   DW     ?                     ;Low word of file's size
  65. hi_size   DW     ?                     ;High word of file's size
  66. name      DB     13 DUP (?)           ;ASCIIZ string of NAME.EXT.  No
  67.                        ;embedded spaces.
  68. dos2DTA   ENDS
  69.  
  70. dirDTA      dos2DTA <>               ;DTA for DOS 2+ directory searches
  71.  
  72.           ENDIF                        ;dos2dirs EQ 'Y'
  73.  
  74.           IF params EQ 'Y'
  75.  
  76. ; Filename separators: tab, space, +, comma, period, :, ;, =
  77. fnm_sep   DB     9,32,43,44,46,58,59,61
  78. lfnm_sep  EQU     THIS BYTE - fnm_sep
  79.  
  80. ; Filename terminators: ', <, >, |, /, ", [, ]
  81. fnm_term  DB     37, 60, 62, 124, 47, 34, 91, 93
  82. lfnm_trm  EQU     THIS BYTE - fnm_term
  83.  
  84. saved_cx  DW     ?               ;Saved CX
  85.  
  86.           ENDIF                        ;params EQ 'Y'
  87.  
  88. ;-----------------------------------------------------------------------------
  89.  
  90. entry:
  91.  
  92.           IF params EQ 'Y'
  93.  
  94.       MOV     CL,cmdcnt           ;Count of parameter characters
  95.       CMP     CL,0               ;Are there any parameter characters?
  96.       JG     someparm           ;Yes.  Process them
  97.  
  98. ;No parameters
  99. ;INSERT DEFAULT CODE HERE
  100.       JMP     endparam           ;To main program
  101.  
  102. ;Parameters
  103. someparm: XOR     CH,CH               ;Change CX to integer count of chars
  104.       ADD     CX,OFFSET cmdcnt      ;Offset of last character => CX
  105.       MOV     saved_cx,CX           ;Save offset of last character
  106.       MOV     DI,OFFSET cmdstr      ;Offset of first character => DI
  107.  
  108. ;INSERT PARAMETER HANDLING CODE HERE
  109.  
  110. ;      getpchar does the following things:
  111. ;      If DI indexes a character in the parameter string,
  112. ; 1.  Translates lower case alphabetic characters to upper case.
  113. ; 2.  Sets the translated character into AL.
  114. ; 3.  Sets AH to 0 if the character is not either a filename separator or a
  115. ;     filename terminator, 1 if it is a filename separator or 2 if it is a
  116. ;     filename terminator.
  117. ; 4.  Sets the zero flag on if the character is neither a filename separator
  118. ;     nor a filename terminator, off otherwise.
  119. ; 5.  Increments DI.
  120. ;      If DI indexes a character after the parameter string
  121. ; 1.  Sets AL to 0.
  122. ; 2.  Sets AH to 3.
  123. ; 3.  Sets the zero flag off.
  124. ;
  125. endparam:
  126.           ENDIF                        ;params EQ 'Y'
  127.  
  128.  
  129. ;INSERT MAIN PROGRAM HERE
  130.       MOV     AX,0C06H           ;Clear Keyboard, Direct Keyboard I/O
  131.       MOV     DL,0FFH           ;Accept input if available (throw away)
  132.       INT     21H               ;Clear keyboard buffer
  133.       MOV     AX,4000H           ;Write to file or device
  134.       MOV     BX,Stderr           ;Standard Error handle
  135.       MOV     CX,done_len           ;Bytes to write
  136.       MOV     DX,OFFSET done_mes    ;Pointer to message
  137.       INT     21H               ;Write it
  138. ;-----------------------------------------------------------------------------
  139. ; RETURN TO DOS
  140. ;-----------------------------------------------------------------------------
  141.  
  142.       MOV     AL,exitval           ;Set error level
  143.  
  144. exit_loc: MOV     AH,4CH            ;Terminate process function number
  145.       INT     21H               ;Return to DOS
  146. start      ENDP
  147. ;-----------------------------------------------------------------------------
  148. ; SUBROUTINES
  149. ;-----------------------------------------------------------------------------
  150.  
  151.           IF params EQ 'Y'
  152.  
  153. ;      getpchar does the following things:
  154. ;      If DI indexes a character in the parameter string,
  155. ; 1.  Translates lower case alphabetic characters to upper case.
  156. ; 2.  Sets the translated character into AL.
  157. ; 3.  Sets AH to 0 if the character is not either a filename separator or a
  158. ;     filename terminator, 1 if it is a filename separator or 2 if it is a
  159. ;     filename terminator.
  160. ; 4.  Sets the zero flag on if the character is neither a filename separator
  161. ;     nor a filename terminator, off otherwise.
  162. ; 5.  Increments DI.
  163. ;      If DI indexes a character after the parameter string
  164. ; 1.  Sets AL to 0.
  165. ; 2.  Sets AH to 3.
  166. ; 3.  Sets the zero flag off.
  167.  
  168. getpchar  PROC
  169.  
  170.       CMP     DI,saved_cx           ;Is DI out of the string?
  171.       JLE     gpcinstr           ;No
  172.  
  173.       MOV     AX,0300H           ;3 => AH, 0 => AL
  174.       AND     AH,AH               ;Set zero flag off
  175.       JMP     gpc_exit           ;Done
  176.  
  177. gpcinstr: MOV     AL,[DI]           ;Character => AL
  178.       INC     DI               ;Point DI at next character
  179.  
  180.       MOV     CX,OFFSET fnm_sep     ;Start check for filename separator
  181.       MOV     BX,CX
  182.       MOV     CX,lfnm_sep           ;Number of characters to compare
  183. gpc_sep:  MOV     AH,[BX]           ;Separator byte
  184.       INC     BX               ;Prepare for next separator byte
  185.       CMP     AH,AL               ;Is it the parameter byte
  186.       LOOPNZ gpc_sep           ;No and another separator byte.
  187.       JNE     gpcnosep           ;Done checking separator bytes.
  188.       MOV     AH,1               ;This is a separator byte
  189.       AND     AH,AH               ;Turn zero flag off
  190.       JMP     gpc_exit           ;Done
  191.  
  192.  
  193. gpcnosep: MOV     CX,OFFSET fnm_term    ;Start check for filename terminator
  194.       MOV     BX,CX
  195.       MOV     CX,lfnm_sep           ;Number of characters to compare
  196. gpc_term: MOV     AH,[BX]           ;Terminator byte
  197.       INC     BX               ;Prepare for next terminator byte
  198.       CMP     AH,AL               ;Is it the parameter byte
  199.       LOOPNZ gpc_term           ;No and another terminator byte.
  200.       JZ     gpc_trm1           ;Jump if this is a terminator byte.
  201.       XOR     AH,AH               ;Convert parameter byte to integer
  202.       CMP     AX,32               ;Is it a control character?
  203.       JL     gpc_trm1           ;Yes
  204.       CMP     AX,127            ;Again, is it a control character?
  205.       JLE     gpcnotrm           ;No.  In legal filename set
  206. gpc_trm1: MOV     AH,2               ;This is a terminator byte
  207.       AND     AH,AH               ;Turn zero flag off
  208.       JMP     gpc_exit           ;Done
  209.  
  210. gpcnotrm: CMP    AL,'a'                ;Check for lower case letter
  211.       JL     gpc_zero
  212.           CMP    AL,'z'
  213.       JG     gpc_zero
  214.           ADD    AX,'A'-'a'            ;Convert to upper case
  215. gpc_zero: XOR     AH,AH               ;Turn zero flag on
  216.  
  217. gpc_exit: RET
  218. getpchar  ENDP
  219.  
  220.           ENDIF                        ;params EQ 'Y'
  221.  
  222. ;-----------------------------------------------------------------------------
  223. ; OVERALL END
  224. ;-----------------------------------------------------------------------------
  225. COMSEG      ENDS
  226.       END     start
  227.